package com.share.mybatis.main;

import com.share.common.service.BaseService;
import com.share.jdbc.service.OrderServiceImpl;
import com.share.jdbc.service.UserServiceImpl;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

/**
 * @desc: mybatis基于命名空间的分库分表
 * @author:caifan
 * @date:2020/11/22
 */
public class MybatisMain {

    private static final String CONFIG_FILE = "mybatis/application-sharding-databases.xml";
//    private static final String CONFIG_FILE = "mybatis/application-sharding-tables.xml";
//    private static final String CONFIG_FILE = "mybatis/application-sharding-databases-tables.xml";
//    private static final String CONFIG_FILE = "mybatis/application-master-slave.xml";
//    private static final String CONFIG_FILE = "mybatis/application-sharding-master-slave.xml";

    public static void main(final String[] args) throws SQLException {
        try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_FILE)) {
            BaseService orderService = applicationContext.getBean("orderService", BaseService.class);
            BaseService userService = applicationContext.getBean("userService", BaseService.class);
            orderService.initEnvironment();
            orderService.processSuccess();

            userService.initEnvironment();
            userService.processSuccess();
        }
    }
}
